package com.eve.springcloud.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;

@RestController
public class FlowLimitController {
	
	@GetMapping("/testA")
	public String testA() {
		return "---testA123---";
	}
	
	@GetMapping("/testB")
	public String testB() {
		return "---testB---";
	}
	
	@GetMapping("/testD")
	public String testD() {
		System.out.println("测试异常比例");
		int age = 10/0;
		return "---testD 异常比例---";
	}
	
	@GetMapping("/testE")
	public String testE() {
		System.out.println("测试异常数");
		int age = 10/0;
		return "---testE 异常数---";
	}
	
	/**
	 * 热点Key限流 20200707
	 * @return
	 */
	@GetMapping("/testk")
	@SentinelResource(value = "testk", blockHandler = "deal_testk")
	public String testHotKey(@RequestParam(value = "p1", required = false) String p1
							,@RequestParam(value = "p2", required = false) String p2) {
		System.out.println("热点Key限流");
		
		return "---testHotKey---";
	}
	/**
	 * 设置的自定义限流返回方法
	 * @param p1
	 * @param p2
	 * @param exception
	 * @return
	 */
	public String deal_testk(String p1, String p2, BlockException exception) {
		return "----对不起，网络不见了，o(+||__||+)o";
	}
	
	
}
